package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/9 17:35
 */
public class M0501 {


    public static int insertBits(int N, int M, int i, int j) {
        int mask = ((1 << (j - i + 1)) - 1) << i;
        mask = ~mask;
        N &= mask;
        M = M << i;
        return M | N;
    }


    // for test
    public static void main(String[] args) {
        int N = 1024,
                M = 19,
                i = 2,
                j = 6;
        System.out.println(insertBits(N, M, i, j));
    }


}
